/*
 * Copyright (c) 2011-2014, fortiss GmbH.
 * Licensed under the Apache License, Version 2.0.
 *
 * Use, modification and distribution are subject to the terms specified
 * in the accompanying license file LICENSE.txt located at the root directory
 * of this software distribution. A copy is available at
 * http://chromosome.fortiss.org/.
 *
 * This file is part of CHROMOSOME.
 *
 * $Id: marshaler.c 7617 2014-02-26 22:13:31Z kainz $
 */

/**
 * \file
 *
 * \brief  Waypoint that marshals topic data for network transportation.
 *
 * \author
 *         This file has been generated by the CHROMOSOME Modeling Tool (fortiss GmbH).
 */

/******************************************************************************/
/***   Includes                                                             ***/
/******************************************************************************/
#include "xme/wp/marshal/include/marshaler.h"
#include "xme/wp/marshal/include/marshalerInternalTypes.h"
#include "xme/wp/marshal/include-gen/marshaler.h"

#include "detector/topic/dictionary.h"
#include "detector/topic/dictionaryData.h"

#include "xme/hal/include/mem.h"
#include "xme/hal/include/net.h"
#include "xme/hal/include/table.h"

#include "xme/core/dataHandler/include/dataHandler.h"
#include "xme/core/topic.h"
#include "xme/core/topicData.h"

#include <inttypes.h>

/******************************************************************************/
/***   Variables                                                            ***/
/******************************************************************************/
/**
 * \brief Constant array that contains all topics that are supported by this
 *        marshaler.
 */
static const xme_core_topic_t
supportedTopics[] =
{
    DETECTOR_TOPIC_DEVICE_INFO,
    XME_CORE_TOPIC_PNPMANAGER_RUNTIME_GRAPH_MODEL,
    XME_CORE_TOPIC_LOGIN_LOGINREQUEST,
    XME_CORE_TOPIC_LOGIN_LOGINRESPONSE,
    XME_CORE_TOPIC_LOGIN_PNPLOGINREQUEST,
    XME_CORE_TOPIC_LOGIN_PNPLOGINRESPONSE,
    XME_CORE_TOPIC_LOGIN_LOGINACKNOWLEDGMENT,
    XME_CORE_TOPIC_PNP_COMPONENTINSTANCEMANIFEST,
    XME_CORE_TOPIC_PNP_LOGOUTACKNOWLEDGMENT,
    XME_CORE_TOPIC_PNP_LOGOUTREQUEST,
    XME_CORE_TOPIC_PNP_LOGOUTNOTIFICATION,
    XME_CORE_TOPIC_PNP_REMOVECOMPONENTREQUEST
};

/******************************************************************************/
/***   Prototypes                                                           ***/
/******************************************************************************/
/**
 * \brief  Performs marshaling on the given topic data.
 *
 * \param  topic      Topic of the data stored at inputPort.
 * \param  inputPort  The inputPort where the data is stored that will be marshaled.
 * \param  outputPort The outputPort where the marshaled data is written to.
 *
 * \retval XME_STATUS_SUCCESS if the data was marshaled successfully.
 * \retval XME_STATUS_UNSUPPORTED if the given topic is not supported by this marshaler.
 * \retval XME_STATUS_INTERNAL_ERROR if an error occurred during reading from the inputPort.
 */
xme_status_t
doMarshaling
(
    xme_core_topic_t topic,
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort
);

/**
 * \brief  Performs marshaling for topic 'device_info'.
 *
 * \param  inputPort Input port where data is stored that will be marshaled.
 * \param  buffer Buffer where marshaled data will be written to.
 *
 * \retval XME_STATUS_SUCCESS if the data was marshaled successfully.
 * \retval XME_STATUS_INTERNAL_ERROR if an error occurred during reading from the inputPort.
 */
xme_status_t
doMarshalingForDevice_info
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
);

/**
 * \brief  Performs marshaling for topic 'pnpManager_runtime_graph_model'.
 *
 * \param  inputPort Input port where data is stored that will be marshaled.
 * \param  buffer Buffer where marshaled data will be written to.
 *
 * \retval XME_STATUS_SUCCESS if the data was marshaled successfully.
 * \retval XME_STATUS_INTERNAL_ERROR if an error occurred during reading from the inputPort.
 */
xme_status_t
doMarshalingForPnpManager_runtime_graph_model
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
);

/**
 * \brief  Performs marshaling for topic 'login_loginRequest'.
 *
 * \param  inputPort Input port where data is stored that will be marshaled.
 * \param  buffer Buffer where marshaled data will be written to.
 *
 * \retval XME_STATUS_SUCCESS if the data was marshaled successfully.
 * \retval XME_STATUS_INTERNAL_ERROR if an error occurred during reading from the inputPort.
 */
xme_status_t
doMarshalingForLogin_loginRequest
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
);

/**
 * \brief  Performs marshaling for topic 'login_loginResponse'.
 *
 * \param  inputPort Input port where data is stored that will be marshaled.
 * \param  buffer Buffer where marshaled data will be written to.
 *
 * \retval XME_STATUS_SUCCESS if the data was marshaled successfully.
 * \retval XME_STATUS_INTERNAL_ERROR if an error occurred during reading from the inputPort.
 */
xme_status_t
doMarshalingForLogin_loginResponse
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
);

/**
 * \brief  Performs marshaling for topic 'login_pnpLoginRequest'.
 *
 * \param  inputPort Input port where data is stored that will be marshaled.
 * \param  buffer Buffer where marshaled data will be written to.
 *
 * \retval XME_STATUS_SUCCESS if the data was marshaled successfully.
 * \retval XME_STATUS_INTERNAL_ERROR if an error occurred during reading from the inputPort.
 */
xme_status_t
doMarshalingForLogin_pnpLoginRequest
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
);

/**
 * \brief  Performs marshaling for topic 'login_pnpLoginResponse'.
 *
 * \param  inputPort Input port where data is stored that will be marshaled.
 * \param  buffer Buffer where marshaled data will be written to.
 *
 * \retval XME_STATUS_SUCCESS if the data was marshaled successfully.
 * \retval XME_STATUS_INTERNAL_ERROR if an error occurred during reading from the inputPort.
 */
xme_status_t
doMarshalingForLogin_pnpLoginResponse
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
);

/**
 * \brief  Performs marshaling for topic 'login_loginAcknowledgment'.
 *
 * \param  inputPort Input port where data is stored that will be marshaled.
 * \param  buffer Buffer where marshaled data will be written to.
 *
 * \retval XME_STATUS_SUCCESS if the data was marshaled successfully.
 * \retval XME_STATUS_INTERNAL_ERROR if an error occurred during reading from the inputPort.
 */
xme_status_t
doMarshalingForLogin_loginAcknowledgment
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
);

/**
 * \brief  Performs marshaling for topic 'pnp_componentInstanceManifest'.
 *
 * \param  inputPort Input port where data is stored that will be marshaled.
 * \param  buffer Buffer where marshaled data will be written to.
 *
 * \retval XME_STATUS_SUCCESS if the data was marshaled successfully.
 * \retval XME_STATUS_INTERNAL_ERROR if an error occurred during reading from the inputPort.
 */
xme_status_t
doMarshalingForPnp_componentInstanceManifest
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
);

/**
 * \brief  Performs marshaling for topic 'pnp_logoutAcknowledgment'.
 *
 * \param  inputPort Input port where data is stored that will be marshaled.
 * \param  buffer Buffer where marshaled data will be written to.
 *
 * \retval XME_STATUS_SUCCESS if the data was marshaled successfully.
 * \retval XME_STATUS_INTERNAL_ERROR if an error occurred during reading from the inputPort.
 */
xme_status_t
doMarshalingForPnp_logoutAcknowledgment
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
);

/**
 * \brief  Performs marshaling for topic 'pnp_logoutRequest'.
 *
 * \param  inputPort Input port where data is stored that will be marshaled.
 * \param  buffer Buffer where marshaled data will be written to.
 *
 * \retval XME_STATUS_SUCCESS if the data was marshaled successfully.
 * \retval XME_STATUS_INTERNAL_ERROR if an error occurred during reading from the inputPort.
 */
xme_status_t
doMarshalingForPnp_logoutRequest
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
);

/**
 * \brief  Performs marshaling for topic 'pnp_logoutNotification'.
 *
 * \param  inputPort Input port where data is stored that will be marshaled.
 * \param  buffer Buffer where marshaled data will be written to.
 *
 * \retval XME_STATUS_SUCCESS if the data was marshaled successfully.
 * \retval XME_STATUS_INTERNAL_ERROR if an error occurred during reading from the inputPort.
 */
xme_status_t
doMarshalingForPnp_logoutNotification
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
);

/**
 * \brief  Performs marshaling for topic 'pnp_removeComponentRequest'.
 *
 * \param  inputPort Input port where data is stored that will be marshaled.
 * \param  buffer Buffer where marshaled data will be written to.
 *
 * \retval XME_STATUS_SUCCESS if the data was marshaled successfully.
 * \retval XME_STATUS_INTERNAL_ERROR if an error occurred during reading from the inputPort.
 */
xme_status_t
doMarshalingForPnp_removeComponentRequest
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
);

/******************************************************************************/
/***   Implementation                                                       ***/
/******************************************************************************/
xme_status_t
xme_wp_marshal_marshaler_run
(
    xme_wp_waypoint_instanceId_t instanceId
)
{
    xme_status_t status;
    xme_wp_marshal_marshaler_configurationItem_t* configurationItem;

    configurationItem = XME_HAL_TABLE_ITEM_FROM_HANDLE
    (
        xme_wp_marshal_marshaler_configurationTable,
        (xme_hal_table_rowHandle_t)instanceId
    );

    XME_CHECK
    (
        NULL != configurationItem,
        XME_STATUS_INVALID_HANDLE
    );

    // Do the marshaling for this configuration
    status = doMarshaling
    (
        configurationItem->topic,
        configurationItem->inputPort,
        configurationItem->outputPort
    );

    XME_CHECK
    (
        XME_STATUS_SUCCESS == status,
        XME_STATUS_INTERNAL_ERROR
    );

    return XME_STATUS_SUCCESS;
}

xme_status_t
doMarshaling
(
    xme_core_topic_t topic,
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort
)
{
    void* buffer;
    unsigned int bufferSize;
    xme_status_t status;

    XME_CHECK(XME_STATUS_SUCCESS == xme_core_dataHandler_startReadOperation(inputPort), XME_STATUS_INTERNAL_ERROR);
    XME_CHECK(XME_STATUS_SUCCESS == xme_core_dataHandler_startWriteOperation(outputPort), XME_STATUS_INTERNAL_ERROR);

    // Switch for the correct topic
    // In the respective cases we allocate a buffer with the right size for the topic and
    // call a function that performs the read from the inputPort and the actual marshaling
    if (DETECTOR_TOPIC_DEVICE_INFO == topic)
    {
        uint8_t marshaledData[52];
        
        buffer = marshaledData;
        bufferSize = 52;
        
        status = doMarshalingForDevice_info
        (
            inputPort,
            outputPort,
            (void*)marshaledData
        );
    }
    else if (XME_CORE_TOPIC_PNPMANAGER_RUNTIME_GRAPH_MODEL == topic)
    {
        uint8_t marshaledData[28208];
        
        buffer = marshaledData;
        bufferSize = 28208;
        
        status = doMarshalingForPnpManager_runtime_graph_model
        (
            inputPort,
            outputPort,
            (void*)marshaledData
        );
    }
    else if (XME_CORE_TOPIC_LOGIN_LOGINREQUEST == topic)
    {
        uint8_t marshaledData[274];
        
        buffer = marshaledData;
        bufferSize = 274;
        
        status = doMarshalingForLogin_loginRequest
        (
            inputPort,
            outputPort,
            (void*)marshaledData
        );
    }
    else if (XME_CORE_TOPIC_LOGIN_LOGINRESPONSE == topic)
    {
        uint8_t marshaledData[26];
        
        buffer = marshaledData;
        bufferSize = 26;
        
        status = doMarshalingForLogin_loginResponse
        (
            inputPort,
            outputPort,
            (void*)marshaledData
        );
    }
    else if (XME_CORE_TOPIC_LOGIN_PNPLOGINREQUEST == topic)
    {
        uint8_t marshaledData[10];
        
        buffer = marshaledData;
        bufferSize = 10;
        
        status = doMarshalingForLogin_pnpLoginRequest
        (
            inputPort,
            outputPort,
            (void*)marshaledData
        );
    }
    else if (XME_CORE_TOPIC_LOGIN_PNPLOGINRESPONSE == topic)
    {
        uint8_t marshaledData[14];
        
        buffer = marshaledData;
        bufferSize = 14;
        
        status = doMarshalingForLogin_pnpLoginResponse
        (
            inputPort,
            outputPort,
            (void*)marshaledData
        );
    }
    else if (XME_CORE_TOPIC_LOGIN_LOGINACKNOWLEDGMENT == topic)
    {
        uint8_t marshaledData[4];
        
        buffer = marshaledData;
        bufferSize = 4;
        
        status = doMarshalingForLogin_loginAcknowledgment
        (
            inputPort,
            outputPort,
            (void*)marshaledData
        );
    }
    else if (XME_CORE_TOPIC_PNP_COMPONENTINSTANCEMANIFEST == topic)
    {
        uint8_t marshaledData[4284];
        
        buffer = marshaledData;
        bufferSize = 4284;
        
        status = doMarshalingForPnp_componentInstanceManifest
        (
            inputPort,
            outputPort,
            (void*)marshaledData
        );
    }
    else if (XME_CORE_TOPIC_PNP_LOGOUTACKNOWLEDGMENT == topic)
    {
        uint8_t marshaledData[4];
        
        buffer = marshaledData;
        bufferSize = 4;
        
        status = doMarshalingForPnp_logoutAcknowledgment
        (
            inputPort,
            outputPort,
            (void*)marshaledData
        );
    }
    else if (XME_CORE_TOPIC_PNP_LOGOUTREQUEST == topic)
    {
        uint8_t marshaledData[4];
        
        buffer = marshaledData;
        bufferSize = 4;
        
        status = doMarshalingForPnp_logoutRequest
        (
            inputPort,
            outputPort,
            (void*)marshaledData
        );
    }
    else if (XME_CORE_TOPIC_PNP_LOGOUTNOTIFICATION == topic)
    {
        uint8_t marshaledData[4];
        
        buffer = marshaledData;
        bufferSize = 4;
        
        status = doMarshalingForPnp_logoutNotification
        (
            inputPort,
            outputPort,
            (void*)marshaledData
        );
    }
    else if (XME_CORE_TOPIC_PNP_REMOVECOMPONENTREQUEST == topic)
    {
        uint8_t marshaledData[8];
        
        buffer = marshaledData;
        bufferSize = 8;
        
        status = doMarshalingForPnp_removeComponentRequest
        (
            inputPort,
            outputPort,
            (void*)marshaledData
        );
    }
    else
    {
        XME_LOG
        (
            XME_LOG_ERROR,
            "xme_wp_marshal_marshaler_run(): Given topic with id %" PRIu64 " is not "
            "supported by this marshaler.",
            topic
        );
        return XME_STATUS_INTERNAL_ERROR;
    }

    XME_CHECK
    (
        XME_STATUS_SUCCESS == status,
        XME_STATUS_INTERNAL_ERROR
    );

    // Write marshaled data to outputPort
    status = xme_core_dataHandler_writeData
    (
        outputPort,
        buffer,
        bufferSize
    );

    XME_CHECK
    (
        XME_STATUS_SUCCESS == status,
        XME_STATUS_INTERNAL_ERROR
    );

    XME_CHECK(XME_STATUS_SUCCESS == xme_core_dataHandler_completeWriteOperation(outputPort), XME_STATUS_INTERNAL_ERROR);
    XME_CHECK(XME_STATUS_SUCCESS == xme_core_dataHandler_completeReadOperation(inputPort), XME_STATUS_INTERNAL_ERROR);

    return XME_STATUS_SUCCESS;
}


xme_status_t
doMarshalingForDevice_info
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
)
{
    detector_topic_device_info_t topicData;
    unsigned int topicDataSize;
    unsigned int bytesRead;
    uint8_t* bufferPtr;
    xme_status_t status;


    topicDataSize = sizeof(detector_topic_device_info_t);

    // Read topic data
    status = xme_core_dataHandler_readData
    (
        inputPort,
        &topicData,
        topicDataSize,
        &bytesRead
    );

    XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    XME_CHECK(bytesRead == topicDataSize, XME_STATUS_INTERNAL_ERROR);

    // Marshal topic data
    bufferPtr = (uint8_t*)buffer;
    
    // char topicData.name
    {
        uint8_t i0;
        
        for (i0 = 0; i0 < 50; i0++)
        {
            // char topicData.name[i0]
            xme_hal_mem_copy(bufferPtr, &topicData.name[i0], sizeof(char));
            bufferPtr += sizeof(char);
        }
    }
    
    // uint16_t topicData.counter
    {
        uint16_t netValue;
    
        netValue = xme_hal_net_htons((uint16_t)topicData.counter);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint16_t));
        bufferPtr += sizeof(uint16_t);
    }

    // Marshal attributes

    // uint32_t channelID
    {
        uint32_t attributeValue;
        uint8_t marshaledAttribute[4];
        uint8_t* bufferPtr;
    
        bufferPtr = marshaledAttribute;
    
        status = xme_core_dataHandler_readAttribute
        (
            inputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            &attributeValue,
            sizeof(attributeValue),
            &bytesRead
        );
    
        XME_CHECK(XME_STATUS_SUCCESS == status || XME_STATUS_NO_SUCH_VALUE == status, XME_STATUS_INTERNAL_ERROR);
        XME_CHECK(XME_STATUS_NO_SUCH_VALUE == status || bytesRead == sizeof(uint32_t), XME_STATUS_INTERNAL_ERROR);
    
        // uint32_t attributeValue
        {
            uint32_t netValue;
        
            netValue = xme_hal_net_htonl((uint32_t)attributeValue);
            xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
            bufferPtr += sizeof(uint32_t);
        }
    
        status = xme_core_dataHandler_writeAttribute
        (
            outputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            marshaledAttribute,
            4
        );
    
        XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    }

    return XME_STATUS_SUCCESS;
}


xme_status_t
doMarshalingForPnpManager_runtime_graph_model
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
)
{
    xme_core_topic_pnpManager_runtime_graph_model_t topicData;
    unsigned int topicDataSize;
    unsigned int bytesRead;
    uint8_t* bufferPtr;
    xme_status_t status;


    topicDataSize = sizeof(xme_core_topic_pnpManager_runtime_graph_model_t);

    // Read topic data
    status = xme_core_dataHandler_readData
    (
        inputPort,
        &topicData,
        topicDataSize,
        &bytesRead
    );

    XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    XME_CHECK(bytesRead == topicDataSize, XME_STATUS_INTERNAL_ERROR);

    // Marshal topic data
    bufferPtr = (uint8_t*)buffer;
    
    // enum topicData.action
    {
        uint32_t netValue;
    
        netValue = xme_hal_net_htonl((uint32_t)topicData.action);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
        bufferPtr += sizeof(uint32_t);
    }
    
    // uint32_t topicData.nodeId
    {
        uint32_t netValue;
    
        netValue = xme_hal_net_htonl((uint32_t)topicData.nodeId);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
        bufferPtr += sizeof(uint32_t);
    }
    
    // struct topicData.vertex
    {
        uint8_t i0;
        
        for (i0 = 0; i0 < 60; i0++)
        {
            // struct topicData.vertex[i0]
            {
                // enum topicData.vertex[i0].vertexType
                {
                    uint32_t netValue;
                
                    netValue = xme_hal_net_htonl((uint32_t)topicData.vertex[i0].vertexType);
                    xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
                    bufferPtr += sizeof(uint32_t);
                }
                
                // char topicData.vertex[i0].vertexData
                {
                    uint16_t i1;
                    
                    for (i1 = 0; i1 < 256; i1++)
                    {
                        // char topicData.vertex[i0].vertexData[i1]
                        xme_hal_mem_copy(bufferPtr, &topicData.vertex[i0].vertexData[i1], sizeof(char));
                        bufferPtr += sizeof(char);
                    }
                }
                
                // uint32_t topicData.vertex[i0].componentType
                {
                    uint32_t netValue;
                
                    netValue = xme_hal_net_htonl((uint32_t)topicData.vertex[i0].componentType);
                    xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
                    bufferPtr += sizeof(uint32_t);
                }
                
                // uint32_t topicData.vertex[i0].componentId
                {
                    uint32_t netValue;
                
                    netValue = xme_hal_net_htonl((uint32_t)topicData.vertex[i0].componentId);
                    xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
                    bufferPtr += sizeof(uint32_t);
                }
                
                // uint32_t topicData.vertex[i0].componentHandle
                {
                    uint32_t netValue;
                
                    netValue = xme_hal_net_htonl((uint32_t)topicData.vertex[i0].componentHandle);
                    xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
                    bufferPtr += sizeof(uint32_t);
                }
                
                // struct topicData.vertex[i0].portData
                {
                    uint8_t i1;
                    
                    for (i1 = 0; i1 < 32; i1++)
                    {
                        // struct topicData.vertex[i0].portData[i1]
                        {
                            // uint8_t topicData.vertex[i0].portData[i1].queueSize
                            {
                                uint8_t netValue;
                            
                                netValue = (uint8_t)topicData.vertex[i0].portData[i1].queueSize;
                                xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint8_t));
                                bufferPtr += sizeof(uint8_t);
                            }
                        }
                    }
                }
                
                // struct topicData.vertex[i0].functionData
                {
                    uint8_t i1;
                    
                    for (i1 = 0; i1 < 16; i1++)
                    {
                        // struct topicData.vertex[i0].functionData[i1]
                        {
                            // uint64_t topicData.vertex[i0].functionData[i1].executionPeriod
                            {
                                uint64_t netValue;
                            
                                netValue = xme_hal_net_htonll((uint64_t)topicData.vertex[i0].functionData[i1].executionPeriod);
                                xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint64_t));
                                bufferPtr += sizeof(uint64_t);
                            }
                        }
                    }
                }
            }
        }
    }
    
    // struct topicData.edge
    {
        uint8_t i0;
        
        for (i0 = 0; i0 < 60; i0++)
        {
            // struct topicData.edge[i0]
            {
                // uint8_t topicData.edge[i0].srcVertexIndex
                {
                    uint8_t netValue;
                
                    netValue = (uint8_t)topicData.edge[i0].srcVertexIndex;
                    xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint8_t));
                    bufferPtr += sizeof(uint8_t);
                }
                
                // uint8_t topicData.edge[i0].sinkVertexIndex
                {
                    uint8_t netValue;
                
                    netValue = (uint8_t)topicData.edge[i0].sinkVertexIndex;
                    xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint8_t));
                    bufferPtr += sizeof(uint8_t);
                }
                
                // enum topicData.edge[i0].edgeType
                {
                    uint32_t netValue;
                
                    netValue = xme_hal_net_htonl((uint32_t)topicData.edge[i0].edgeType);
                    xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
                    bufferPtr += sizeof(uint32_t);
                }
                
                // char topicData.edge[i0].edgeData
                {
                    uint8_t i1;
                    
                    for (i1 = 0; i1 < 32; i1++)
                    {
                        // char topicData.edge[i0].edgeData[i1]
                        xme_hal_mem_copy(bufferPtr, &topicData.edge[i0].edgeData[i1], sizeof(char));
                        bufferPtr += sizeof(char);
                    }
                }
            }
        }
    }

    // Marshal attributes

    // uint32_t channelID
    {
        uint32_t attributeValue;
        uint8_t marshaledAttribute[4];
        uint8_t* bufferPtr;
    
        bufferPtr = marshaledAttribute;
    
        status = xme_core_dataHandler_readAttribute
        (
            inputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            &attributeValue,
            sizeof(attributeValue),
            &bytesRead
        );
    
        XME_CHECK(XME_STATUS_SUCCESS == status || XME_STATUS_NO_SUCH_VALUE == status, XME_STATUS_INTERNAL_ERROR);
        XME_CHECK(XME_STATUS_NO_SUCH_VALUE == status || bytesRead == sizeof(uint32_t), XME_STATUS_INTERNAL_ERROR);
    
        // uint32_t attributeValue
        {
            uint32_t netValue;
        
            netValue = xme_hal_net_htonl((uint32_t)attributeValue);
            xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
            bufferPtr += sizeof(uint32_t);
        }
    
        status = xme_core_dataHandler_writeAttribute
        (
            outputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            marshaledAttribute,
            4
        );
    
        XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    }

    return XME_STATUS_SUCCESS;
}


xme_status_t
doMarshalingForLogin_loginRequest
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
)
{
    xme_core_topic_login_loginRequest_t topicData;
    unsigned int topicDataSize;
    unsigned int bytesRead;
    uint8_t* bufferPtr;
    xme_status_t status;


    topicDataSize = sizeof(xme_core_topic_login_loginRequest_t);

    // Read topic data
    status = xme_core_dataHandler_readData
    (
        inputPort,
        &topicData,
        topicDataSize,
        &bytesRead
    );

    XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    XME_CHECK(bytesRead == topicDataSize, XME_STATUS_INTERNAL_ERROR);

    // Marshal topic data
    bufferPtr = (uint8_t*)buffer;
    
    // uint64_t topicData.guid
    {
        uint64_t netValue;
    
        netValue = xme_hal_net_htonll((uint64_t)topicData.guid);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint64_t));
        bufferPtr += sizeof(uint64_t);
    }
    
    // uint32_t topicData.nodeId
    {
        uint32_t netValue;
    
        netValue = xme_hal_net_htonl((uint32_t)topicData.nodeId);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
        bufferPtr += sizeof(uint32_t);
    }
    
    // char topicData.nodeName
    {
        uint16_t i0;
        
        for (i0 = 0; i0 < 256; i0++)
        {
            // char topicData.nodeName[i0]
            xme_hal_mem_copy(bufferPtr, &topicData.nodeName[i0], sizeof(char));
            bufferPtr += sizeof(char);
        }
    }
    
    // uint32_t topicData.ipAddress
    {
        uint32_t netValue;
    
        netValue = xme_hal_net_htonl((uint32_t)topicData.ipAddress);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
        bufferPtr += sizeof(uint32_t);
    }
    
    // uint16_t topicData.portAddress
    {
        uint16_t netValue;
    
        netValue = xme_hal_net_htons((uint16_t)topicData.portAddress);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint16_t));
        bufferPtr += sizeof(uint16_t);
    }

    // Marshal attributes

    // uint32_t channelID
    {
        uint32_t attributeValue;
        uint8_t marshaledAttribute[4];
        uint8_t* bufferPtr;
    
        bufferPtr = marshaledAttribute;
    
        status = xme_core_dataHandler_readAttribute
        (
            inputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            &attributeValue,
            sizeof(attributeValue),
            &bytesRead
        );
    
        XME_CHECK(XME_STATUS_SUCCESS == status || XME_STATUS_NO_SUCH_VALUE == status, XME_STATUS_INTERNAL_ERROR);
        XME_CHECK(XME_STATUS_NO_SUCH_VALUE == status || bytesRead == sizeof(uint32_t), XME_STATUS_INTERNAL_ERROR);
    
        // uint32_t attributeValue
        {
            uint32_t netValue;
        
            netValue = xme_hal_net_htonl((uint32_t)attributeValue);
            xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
            bufferPtr += sizeof(uint32_t);
        }
    
        status = xme_core_dataHandler_writeAttribute
        (
            outputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            marshaledAttribute,
            4
        );
    
        XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    }

    return XME_STATUS_SUCCESS;
}


xme_status_t
doMarshalingForLogin_loginResponse
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
)
{
    xme_core_topic_login_loginResponse_t topicData;
    unsigned int topicDataSize;
    unsigned int bytesRead;
    uint8_t* bufferPtr;
    xme_status_t status;


    topicDataSize = sizeof(xme_core_topic_login_loginResponse_t);

    // Read topic data
    status = xme_core_dataHandler_readData
    (
        inputPort,
        &topicData,
        topicDataSize,
        &bytesRead
    );

    XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    XME_CHECK(bytesRead == topicDataSize, XME_STATUS_INTERNAL_ERROR);

    // Marshal topic data
    bufferPtr = (uint8_t*)buffer;
    
    // enum topicData.loginStatus
    {
        uint32_t netValue;
    
        netValue = xme_hal_net_htonl((uint32_t)topicData.loginStatus);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
        bufferPtr += sizeof(uint32_t);
    }
    
    // uint64_t topicData.guid
    {
        uint64_t netValue;
    
        netValue = xme_hal_net_htonll((uint64_t)topicData.guid);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint64_t));
        bufferPtr += sizeof(uint64_t);
    }
    
    // uint32_t topicData.nodeId
    {
        uint32_t netValue;
    
        netValue = xme_hal_net_htonl((uint32_t)topicData.nodeId);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
        bufferPtr += sizeof(uint32_t);
    }
    
    // uint32_t topicData.channelID
    {
        uint32_t netValue;
    
        netValue = xme_hal_net_htonl((uint32_t)topicData.channelID);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
        bufferPtr += sizeof(uint32_t);
    }
    
    // uint32_t topicData.ipAddress
    {
        uint32_t netValue;
    
        netValue = xme_hal_net_htonl((uint32_t)topicData.ipAddress);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
        bufferPtr += sizeof(uint32_t);
    }
    
    // uint16_t topicData.portAddress
    {
        uint16_t netValue;
    
        netValue = xme_hal_net_htons((uint16_t)topicData.portAddress);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint16_t));
        bufferPtr += sizeof(uint16_t);
    }

    // Marshal attributes

    // uint32_t channelID
    {
        uint32_t attributeValue;
        uint8_t marshaledAttribute[4];
        uint8_t* bufferPtr;
    
        bufferPtr = marshaledAttribute;
    
        status = xme_core_dataHandler_readAttribute
        (
            inputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            &attributeValue,
            sizeof(attributeValue),
            &bytesRead
        );
    
        XME_CHECK(XME_STATUS_SUCCESS == status || XME_STATUS_NO_SUCH_VALUE == status, XME_STATUS_INTERNAL_ERROR);
        XME_CHECK(XME_STATUS_NO_SUCH_VALUE == status || bytesRead == sizeof(uint32_t), XME_STATUS_INTERNAL_ERROR);
    
        // uint32_t attributeValue
        {
            uint32_t netValue;
        
            netValue = xme_hal_net_htonl((uint32_t)attributeValue);
            xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
            bufferPtr += sizeof(uint32_t);
        }
    
        status = xme_core_dataHandler_writeAttribute
        (
            outputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            marshaledAttribute,
            4
        );
    
        XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    }

    return XME_STATUS_SUCCESS;
}


xme_status_t
doMarshalingForLogin_pnpLoginRequest
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
)
{
    xme_core_topic_login_pnpLoginRequest_t topicData;
    unsigned int topicDataSize;
    unsigned int bytesRead;
    uint8_t* bufferPtr;
    xme_status_t status;


    topicDataSize = sizeof(xme_core_topic_login_pnpLoginRequest_t);

    // Read topic data
    status = xme_core_dataHandler_readData
    (
        inputPort,
        &topicData,
        topicDataSize,
        &bytesRead
    );

    XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    XME_CHECK(bytesRead == topicDataSize, XME_STATUS_INTERNAL_ERROR);

    // Marshal topic data
    bufferPtr = (uint8_t*)buffer;
    
    // uint32_t topicData.nodeId
    {
        uint32_t netValue;
    
        netValue = xme_hal_net_htonl((uint32_t)topicData.nodeId);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
        bufferPtr += sizeof(uint32_t);
    }
    
    // uint32_t topicData.ipAddress
    {
        uint32_t netValue;
    
        netValue = xme_hal_net_htonl((uint32_t)topicData.ipAddress);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
        bufferPtr += sizeof(uint32_t);
    }
    
    // uint16_t topicData.portAddress
    {
        uint16_t netValue;
    
        netValue = xme_hal_net_htons((uint16_t)topicData.portAddress);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint16_t));
        bufferPtr += sizeof(uint16_t);
    }

    // Marshal attributes

    // uint32_t channelID
    {
        uint32_t attributeValue;
        uint8_t marshaledAttribute[4];
        uint8_t* bufferPtr;
    
        bufferPtr = marshaledAttribute;
    
        status = xme_core_dataHandler_readAttribute
        (
            inputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            &attributeValue,
            sizeof(attributeValue),
            &bytesRead
        );
    
        XME_CHECK(XME_STATUS_SUCCESS == status || XME_STATUS_NO_SUCH_VALUE == status, XME_STATUS_INTERNAL_ERROR);
        XME_CHECK(XME_STATUS_NO_SUCH_VALUE == status || bytesRead == sizeof(uint32_t), XME_STATUS_INTERNAL_ERROR);
    
        // uint32_t attributeValue
        {
            uint32_t netValue;
        
            netValue = xme_hal_net_htonl((uint32_t)attributeValue);
            xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
            bufferPtr += sizeof(uint32_t);
        }
    
        status = xme_core_dataHandler_writeAttribute
        (
            outputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            marshaledAttribute,
            4
        );
    
        XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    }

    return XME_STATUS_SUCCESS;
}


xme_status_t
doMarshalingForLogin_pnpLoginResponse
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
)
{
    xme_core_topic_login_pnpLoginResponse_t topicData;
    unsigned int topicDataSize;
    unsigned int bytesRead;
    uint8_t* bufferPtr;
    xme_status_t status;


    topicDataSize = sizeof(xme_core_topic_login_pnpLoginResponse_t);

    // Read topic data
    status = xme_core_dataHandler_readData
    (
        inputPort,
        &topicData,
        topicDataSize,
        &bytesRead
    );

    XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    XME_CHECK(bytesRead == topicDataSize, XME_STATUS_INTERNAL_ERROR);

    // Marshal topic data
    bufferPtr = (uint8_t*)buffer;
    
    // uint32_t topicData.nodeId
    {
        uint32_t netValue;
    
        netValue = xme_hal_net_htonl((uint32_t)topicData.nodeId);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
        bufferPtr += sizeof(uint32_t);
    }
    
    // uint32_t topicData.channelID
    {
        uint32_t netValue;
    
        netValue = xme_hal_net_htonl((uint32_t)topicData.channelID);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
        bufferPtr += sizeof(uint32_t);
    }
    
    // uint32_t topicData.ipAddress
    {
        uint32_t netValue;
    
        netValue = xme_hal_net_htonl((uint32_t)topicData.ipAddress);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
        bufferPtr += sizeof(uint32_t);
    }
    
    // uint16_t topicData.portAddress
    {
        uint16_t netValue;
    
        netValue = xme_hal_net_htons((uint16_t)topicData.portAddress);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint16_t));
        bufferPtr += sizeof(uint16_t);
    }

    // Marshal attributes

    // uint32_t channelID
    {
        uint32_t attributeValue;
        uint8_t marshaledAttribute[4];
        uint8_t* bufferPtr;
    
        bufferPtr = marshaledAttribute;
    
        status = xme_core_dataHandler_readAttribute
        (
            inputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            &attributeValue,
            sizeof(attributeValue),
            &bytesRead
        );
    
        XME_CHECK(XME_STATUS_SUCCESS == status || XME_STATUS_NO_SUCH_VALUE == status, XME_STATUS_INTERNAL_ERROR);
        XME_CHECK(XME_STATUS_NO_SUCH_VALUE == status || bytesRead == sizeof(uint32_t), XME_STATUS_INTERNAL_ERROR);
    
        // uint32_t attributeValue
        {
            uint32_t netValue;
        
            netValue = xme_hal_net_htonl((uint32_t)attributeValue);
            xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
            bufferPtr += sizeof(uint32_t);
        }
    
        status = xme_core_dataHandler_writeAttribute
        (
            outputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            marshaledAttribute,
            4
        );
    
        XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    }

    return XME_STATUS_SUCCESS;
}


xme_status_t
doMarshalingForLogin_loginAcknowledgment
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
)
{
    xme_core_topic_login_loginAcknowledgment_t topicData;
    unsigned int topicDataSize;
    unsigned int bytesRead;
    uint8_t* bufferPtr;
    xme_status_t status;


    topicDataSize = sizeof(xme_core_topic_login_loginAcknowledgment_t);

    // Read topic data
    status = xme_core_dataHandler_readData
    (
        inputPort,
        &topicData,
        topicDataSize,
        &bytesRead
    );

    XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    XME_CHECK(bytesRead == topicDataSize, XME_STATUS_INTERNAL_ERROR);

    // Marshal topic data
    bufferPtr = (uint8_t*)buffer;
    
    // uint32_t topicData.nodeId
    {
        uint32_t netValue;
    
        netValue = xme_hal_net_htonl((uint32_t)topicData.nodeId);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
        bufferPtr += sizeof(uint32_t);
    }

    // Marshal attributes

    // uint32_t channelID
    {
        uint32_t attributeValue;
        uint8_t marshaledAttribute[4];
        uint8_t* bufferPtr;
    
        bufferPtr = marshaledAttribute;
    
        status = xme_core_dataHandler_readAttribute
        (
            inputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            &attributeValue,
            sizeof(attributeValue),
            &bytesRead
        );
    
        XME_CHECK(XME_STATUS_SUCCESS == status || XME_STATUS_NO_SUCH_VALUE == status, XME_STATUS_INTERNAL_ERROR);
        XME_CHECK(XME_STATUS_NO_SUCH_VALUE == status || bytesRead == sizeof(uint32_t), XME_STATUS_INTERNAL_ERROR);
    
        // uint32_t attributeValue
        {
            uint32_t netValue;
        
            netValue = xme_hal_net_htonl((uint32_t)attributeValue);
            xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
            bufferPtr += sizeof(uint32_t);
        }
    
        status = xme_core_dataHandler_writeAttribute
        (
            outputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            marshaledAttribute,
            4
        );
    
        XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    }

    return XME_STATUS_SUCCESS;
}


xme_status_t
doMarshalingForPnp_componentInstanceManifest
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
)
{
    xme_core_topic_pnp_componentInstanceManifest_t topicData;
    unsigned int topicDataSize;
    unsigned int bytesRead;
    uint8_t* bufferPtr;
    xme_status_t status;


    topicDataSize = sizeof(xme_core_topic_pnp_componentInstanceManifest_t);

    // Read topic data
    status = xme_core_dataHandler_readData
    (
        inputPort,
        &topicData,
        topicDataSize,
        &bytesRead
    );

    XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    XME_CHECK(bytesRead == topicDataSize, XME_STATUS_INTERNAL_ERROR);

    // Marshal topic data
    bufferPtr = (uint8_t*)buffer;
    
    // uint32_t topicData.nodeId
    {
        uint32_t netValue;
    
        netValue = xme_hal_net_htonl((uint32_t)topicData.nodeId);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
        bufferPtr += sizeof(uint32_t);
    }
    
    // struct topicData.components
    {
        uint8_t i0;
        
        for (i0 = 0; i0 < 10; i0++)
        {
            // struct topicData.components[i0]
            {
                // uint32_t topicData.components[i0].componentId
                {
                    uint32_t netValue;
                
                    netValue = xme_hal_net_htonl((uint32_t)topicData.components[i0].componentId);
                    xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
                    bufferPtr += sizeof(uint32_t);
                }
                
                // uint32_t topicData.components[i0].componentType
                {
                    uint32_t netValue;
                
                    netValue = xme_hal_net_htonl((uint32_t)topicData.components[i0].componentType);
                    xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
                    bufferPtr += sizeof(uint32_t);
                }
                
                // uint32_t topicData.components[i0].componentHandle
                {
                    uint32_t netValue;
                
                    netValue = xme_hal_net_htonl((uint32_t)topicData.components[i0].componentHandle);
                    xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
                    bufferPtr += sizeof(uint32_t);
                }
                
                // char topicData.components[i0].initializationString
                {
                    uint16_t i1;
                    
                    for (i1 = 0; i1 < 256; i1++)
                    {
                        // char topicData.components[i0].initializationString[i1]
                        xme_hal_mem_copy(bufferPtr, &topicData.components[i0].initializationString[i1], sizeof(char));
                        bufferPtr += sizeof(char);
                    }
                }
                
                // struct topicData.components[i0].portData
                {
                    uint8_t i1;
                    
                    for (i1 = 0; i1 < 32; i1++)
                    {
                        // struct topicData.components[i0].portData[i1]
                        {
                            // uint8_t topicData.components[i0].portData[i1].queueSize
                            {
                                uint8_t netValue;
                            
                                netValue = (uint8_t)topicData.components[i0].portData[i1].queueSize;
                                xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint8_t));
                                bufferPtr += sizeof(uint8_t);
                            }
                        }
                    }
                }
                
                // struct topicData.components[i0].functionData
                {
                    uint8_t i1;
                    
                    for (i1 = 0; i1 < 16; i1++)
                    {
                        // struct topicData.components[i0].functionData[i1]
                        {
                            // uint64_t topicData.components[i0].functionData[i1].executionPeriod
                            {
                                uint64_t netValue;
                            
                                netValue = xme_hal_net_htonll((uint64_t)topicData.components[i0].functionData[i1].executionPeriod);
                                xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint64_t));
                                bufferPtr += sizeof(uint64_t);
                            }
                        }
                    }
                }
            }
        }
    }

    // Marshal attributes

    // uint32_t channelID
    {
        uint32_t attributeValue;
        uint8_t marshaledAttribute[4];
        uint8_t* bufferPtr;
    
        bufferPtr = marshaledAttribute;
    
        status = xme_core_dataHandler_readAttribute
        (
            inputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            &attributeValue,
            sizeof(attributeValue),
            &bytesRead
        );
    
        XME_CHECK(XME_STATUS_SUCCESS == status || XME_STATUS_NO_SUCH_VALUE == status, XME_STATUS_INTERNAL_ERROR);
        XME_CHECK(XME_STATUS_NO_SUCH_VALUE == status || bytesRead == sizeof(uint32_t), XME_STATUS_INTERNAL_ERROR);
    
        // uint32_t attributeValue
        {
            uint32_t netValue;
        
            netValue = xme_hal_net_htonl((uint32_t)attributeValue);
            xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
            bufferPtr += sizeof(uint32_t);
        }
    
        status = xme_core_dataHandler_writeAttribute
        (
            outputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            marshaledAttribute,
            4
        );
    
        XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    }

    return XME_STATUS_SUCCESS;
}


xme_status_t
doMarshalingForPnp_logoutAcknowledgment
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
)
{
    xme_core_topic_pnp_logoutAcknowledgment_t topicData;
    unsigned int topicDataSize;
    unsigned int bytesRead;
    uint8_t* bufferPtr;
    xme_status_t status;


    topicDataSize = sizeof(xme_core_topic_pnp_logoutAcknowledgment_t);

    // Read topic data
    status = xme_core_dataHandler_readData
    (
        inputPort,
        &topicData,
        topicDataSize,
        &bytesRead
    );

    XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    XME_CHECK(bytesRead == topicDataSize, XME_STATUS_INTERNAL_ERROR);

    // Marshal topic data
    bufferPtr = (uint8_t*)buffer;
    
    // uint32_t topicData.nodeId
    {
        uint32_t netValue;
    
        netValue = xme_hal_net_htonl((uint32_t)topicData.nodeId);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
        bufferPtr += sizeof(uint32_t);
    }

    // Marshal attributes

    // uint32_t channelID
    {
        uint32_t attributeValue;
        uint8_t marshaledAttribute[4];
        uint8_t* bufferPtr;
    
        bufferPtr = marshaledAttribute;
    
        status = xme_core_dataHandler_readAttribute
        (
            inputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            &attributeValue,
            sizeof(attributeValue),
            &bytesRead
        );
    
        XME_CHECK(XME_STATUS_SUCCESS == status || XME_STATUS_NO_SUCH_VALUE == status, XME_STATUS_INTERNAL_ERROR);
        XME_CHECK(XME_STATUS_NO_SUCH_VALUE == status || bytesRead == sizeof(uint32_t), XME_STATUS_INTERNAL_ERROR);
    
        // uint32_t attributeValue
        {
            uint32_t netValue;
        
            netValue = xme_hal_net_htonl((uint32_t)attributeValue);
            xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
            bufferPtr += sizeof(uint32_t);
        }
    
        status = xme_core_dataHandler_writeAttribute
        (
            outputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            marshaledAttribute,
            4
        );
    
        XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    }

    return XME_STATUS_SUCCESS;
}


xme_status_t
doMarshalingForPnp_logoutRequest
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
)
{
    xme_core_topic_pnp_logoutRequest_t topicData;
    unsigned int topicDataSize;
    unsigned int bytesRead;
    uint8_t* bufferPtr;
    xme_status_t status;


    topicDataSize = sizeof(xme_core_topic_pnp_logoutRequest_t);

    // Read topic data
    status = xme_core_dataHandler_readData
    (
        inputPort,
        &topicData,
        topicDataSize,
        &bytesRead
    );

    XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    XME_CHECK(bytesRead == topicDataSize, XME_STATUS_INTERNAL_ERROR);

    // Marshal topic data
    bufferPtr = (uint8_t*)buffer;
    
    // uint32_t topicData.nodeId
    {
        uint32_t netValue;
    
        netValue = xme_hal_net_htonl((uint32_t)topicData.nodeId);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
        bufferPtr += sizeof(uint32_t);
    }

    // Marshal attributes

    // uint32_t channelID
    {
        uint32_t attributeValue;
        uint8_t marshaledAttribute[4];
        uint8_t* bufferPtr;
    
        bufferPtr = marshaledAttribute;
    
        status = xme_core_dataHandler_readAttribute
        (
            inputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            &attributeValue,
            sizeof(attributeValue),
            &bytesRead
        );
    
        XME_CHECK(XME_STATUS_SUCCESS == status || XME_STATUS_NO_SUCH_VALUE == status, XME_STATUS_INTERNAL_ERROR);
        XME_CHECK(XME_STATUS_NO_SUCH_VALUE == status || bytesRead == sizeof(uint32_t), XME_STATUS_INTERNAL_ERROR);
    
        // uint32_t attributeValue
        {
            uint32_t netValue;
        
            netValue = xme_hal_net_htonl((uint32_t)attributeValue);
            xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
            bufferPtr += sizeof(uint32_t);
        }
    
        status = xme_core_dataHandler_writeAttribute
        (
            outputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            marshaledAttribute,
            4
        );
    
        XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    }

    return XME_STATUS_SUCCESS;
}


xme_status_t
doMarshalingForPnp_logoutNotification
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
)
{
    xme_core_topic_pnp_logoutNotification_t topicData;
    unsigned int topicDataSize;
    unsigned int bytesRead;
    uint8_t* bufferPtr;
    xme_status_t status;


    topicDataSize = sizeof(xme_core_topic_pnp_logoutNotification_t);

    // Read topic data
    status = xme_core_dataHandler_readData
    (
        inputPort,
        &topicData,
        topicDataSize,
        &bytesRead
    );

    XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    XME_CHECK(bytesRead == topicDataSize, XME_STATUS_INTERNAL_ERROR);

    // Marshal topic data
    bufferPtr = (uint8_t*)buffer;
    
    // uint32_t topicData.nodeId
    {
        uint32_t netValue;
    
        netValue = xme_hal_net_htonl((uint32_t)topicData.nodeId);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
        bufferPtr += sizeof(uint32_t);
    }

    // Marshal attributes

    // uint32_t channelID
    {
        uint32_t attributeValue;
        uint8_t marshaledAttribute[4];
        uint8_t* bufferPtr;
    
        bufferPtr = marshaledAttribute;
    
        status = xme_core_dataHandler_readAttribute
        (
            inputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            &attributeValue,
            sizeof(attributeValue),
            &bytesRead
        );
    
        XME_CHECK(XME_STATUS_SUCCESS == status || XME_STATUS_NO_SUCH_VALUE == status, XME_STATUS_INTERNAL_ERROR);
        XME_CHECK(XME_STATUS_NO_SUCH_VALUE == status || bytesRead == sizeof(uint32_t), XME_STATUS_INTERNAL_ERROR);
    
        // uint32_t attributeValue
        {
            uint32_t netValue;
        
            netValue = xme_hal_net_htonl((uint32_t)attributeValue);
            xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
            bufferPtr += sizeof(uint32_t);
        }
    
        status = xme_core_dataHandler_writeAttribute
        (
            outputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            marshaledAttribute,
            4
        );
    
        XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    }

    return XME_STATUS_SUCCESS;
}


xme_status_t
doMarshalingForPnp_removeComponentRequest
(
    xme_core_dataManager_dataPacketId_t inputPort,
    xme_core_dataManager_dataPacketId_t outputPort,
    void* buffer
)
{
    xme_core_topic_pnp_removeComponentRequest_t topicData;
    unsigned int topicDataSize;
    unsigned int bytesRead;
    uint8_t* bufferPtr;
    xme_status_t status;


    topicDataSize = sizeof(xme_core_topic_pnp_removeComponentRequest_t);

    // Read topic data
    status = xme_core_dataHandler_readData
    (
        inputPort,
        &topicData,
        topicDataSize,
        &bytesRead
    );

    XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    XME_CHECK(bytesRead == topicDataSize, XME_STATUS_INTERNAL_ERROR);

    // Marshal topic data
    bufferPtr = (uint8_t*)buffer;
    
    // uint32_t topicData.nodeId
    {
        uint32_t netValue;
    
        netValue = xme_hal_net_htonl((uint32_t)topicData.nodeId);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
        bufferPtr += sizeof(uint32_t);
    }
    
    // uint32_t topicData.componentId
    {
        uint32_t netValue;
    
        netValue = xme_hal_net_htonl((uint32_t)topicData.componentId);
        xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
        bufferPtr += sizeof(uint32_t);
    }

    // Marshal attributes

    // uint32_t channelID
    {
        uint32_t attributeValue;
        uint8_t marshaledAttribute[4];
        uint8_t* bufferPtr;
    
        bufferPtr = marshaledAttribute;
    
        status = xme_core_dataHandler_readAttribute
        (
            inputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            &attributeValue,
            sizeof(attributeValue),
            &bytesRead
        );
    
        XME_CHECK(XME_STATUS_SUCCESS == status || XME_STATUS_NO_SUCH_VALUE == status, XME_STATUS_INTERNAL_ERROR);
        XME_CHECK(XME_STATUS_NO_SUCH_VALUE == status || bytesRead == sizeof(uint32_t), XME_STATUS_INTERNAL_ERROR);
    
        // uint32_t attributeValue
        {
            uint32_t netValue;
        
            netValue = xme_hal_net_htonl((uint32_t)attributeValue);
            xme_hal_mem_copy(bufferPtr, &netValue, sizeof(uint32_t));
            bufferPtr += sizeof(uint32_t);
        }
    
        status = xme_core_dataHandler_writeAttribute
        (
            outputPort,
            XME_CORE_ATTRIBUTES(XME_CORE_ATTRIBUTE_KEY_CHANNELID),
            marshaledAttribute,
            4
        );
    
        XME_CHECK(status == XME_STATUS_SUCCESS, XME_STATUS_INTERNAL_ERROR);
    }

    return XME_STATUS_SUCCESS;
}

bool
xme_wp_marshal_marshaler_isSupported
(
    xme_core_topic_t topic
)
{
    uint64_t i;
    size_t supportTopicsLength;

    supportTopicsLength = sizeof(supportedTopics) / sizeof(supportedTopics[0]);

    for (i = 0; i < supportTopicsLength; i++)
    {
        if (topic == supportedTopics[i])
        {
            return true;
        }
    }

    return false;
}
